/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ventasInternet.UpDowImagenes;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;


/**
 *
 * @author DESARO03
 */

public class FileUpDoController implements Serializable {

    public FileUpDoController() {
    }

    /** Creates a new instance of FileUpDoController */
    
  public boolean  upFile(String fileName, InputStream in,String destination) {
        try {
            FileOutputStream out = 
                    new FileOutputStream(new File(destination+File.separator+ fileName));
            System.out.println("rutaa "+destination+File.separator+ fileName);
            byte[] buffer = new byte[6124];
	        int bulk;
	        InputStream inputStream = in;
	        while (true) {
                    bulk = inputStream.read(buffer);
                    if (bulk < 0) {
                      break;
                    }
                    out.write(buffer, 0, bulk);
                    out.flush();
                }
                out.close();
                inputStream.close();
            
            return true;
         } catch (IOException e) {
            System.out.println(e.getMessage());
            return false;
        }
    }
}
